<template>
  <view>
    <view class="container">
      <!-- 血压输入框 -->
      <van-field v-model="form.bloodPressure" label="血压值" placeholder="请输入血压值" @change="form.bloodPressure = $event.detail"/>
    
      <!-- 血糖输入框 -->
      <van-field v-model="form.bloodSugar" label="血糖值" placeholder="请输入血糖值" @change="form.bloodSugar = $event.detail"/>
    
      <!-- 睡眠时长输入框 -->
      <van-field v-model="form.sleepDuration" label="睡眠时长（分钟）" placeholder="请输入睡眠时长" type="number" @change="form.sleepDuration = $event.detail"/>
    
      <!-- 步数输入框 -->
      <van-field v-model="form.steps" label="步数" placeholder="请输入步数" type="number" @change="form.steps = $event.detail"/>
    
      <!-- 卡路里输入框 -->
      <van-field v-model="form.calorie" label="卡路里" placeholder="请输入卡路里" type="number" @change="form.calorie = $event.detail"/>
    
      <!-- 饮水量输入框 -->
      <van-field v-model="form.waterIntake" label="饮水量（毫升）" placeholder="请输入饮水量" type="number" @change="form.waterIntake = $event.detail"/>
    
      <!-- 体重输入框 -->
      <van-field v-model="form.weight" label="体重" placeholder="请输入体重" type="number" @change="form.weight = $event.detail"/>
    
      <!-- 提交按钮 -->
      <van-button type="primary" block @click="submitForm">提交</van-button>
    </view>
  </view>
</template>

<script>
  import {
    submitHealthData
  } from '@/api/healthData.js'
  export default {
    data() {
      return {
        form: {
          userId: '',
          bloodPressure: '',
          bloodSugar: '',
          sleepDuration: '',
          steps: '',
          calorie: '',
          waterIntake: '',
          weight: ''
        }
      };
    },
    created() {
      this.form.userId = uni.getStorageSync('userId')
    },
    methods: {
      submitForm() {
        submitHealthData(this.form).then((res)=>{
          console.log(res)
          uni.showToast({
            title: '数据更新成功',
            icon: 'none',
            duration: 1000
          });
        })
        
      }
    }
  };
</script>

<style scoped>
  .container {
    padding: 20px;
  }
</style>